import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus';
import { resolve } from 'path';
import markdown from 'vite-plugin-markdown-vue';

export default defineConfig({
    plugins: [
        markdown(),
        vue({
            include: [/\.vue$/, /\.md$/]
        }),
        vueSetupExtend()
    ],
    resolve: {
        alias: {
            '@': resolve(__dirname, 'src')
        }
    },
    server: {
        port: 8081,
        proxy: {
            '/mockapi': {
                // target: 'https://console-mock.apipost.cn/app/mock/project/1297a365-85ef-4cc0-b7a0-26dad965b94d',
                target: 'https://console-mock.apipost.cn/app/mock/project/a3678e3a-d4e4-40c7-99ef-873b843ab9d9',
                changeOrigin: true,
                rewrite: path => {
                    return path.replace(/^\/mockapi/, '');
                }
            },
            '/zw-api': {
                target: 'http://api-dev.scrm.keyid.cn',
                changeOrigin: true,
                rewrite: path => {
                    return path.replace(/^\/zw-api/, '');
                }
            }
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@use "@/assets/scss/element/index.scss" as *;`
            }
        },
        postcss: {
            plugins: [
                {
                    postcssPlugin: 'internal:charset-removal',
                    AtRule: {
                        charset: atRule => {
                            if (atRule.name === 'charset') {
                                atRule.remove();
                            }
                        }
                    }
                }
            ]
        }
    }
});
